home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / include / mgriP.h < prev    next >
C/C++ Source or Header  |  1993-11-05  |  5KB  |  127 lines

  1. #include <stdio.h>
  2. #include "mg.h"
  3. #include "mgP.h"
  4. #include "mgri.h"
  5. #include "transform.h"
  6. #include <ri/ri.h>
  7.  
  8. typedef struct mgricontext {
  9.   struct mgcontext mgctx;    /* The mgcontext */
  10.   int born;            /* Has window been displayed on the screen? */
  11.   int dying;            /* Is the window being closed from titlebar? */
  12.   int win;            /* window ID, or 0 */
  13.   int standalone;        /* 1 if program ignores appkit, 0 otherwise */
  14.                   /* (determains if events are prcssed by mg) */
  15.   int polymode;            /* method to draw polyhedra via mgri_polylist*/
  16.   int lflushlimit;        /* max polygons per RiPointsPolygon call */
  17.                 /* for RI_LINE representation            */
  18.   int fflushlimit;        /* max polygons per RiPointsPolygon call */
  19.                   /* for RI_PRIMITIVE representation      */
  20.   int drawsfaces;
  21.   Transform W2C;        /* current W2C xform */
  22.   Transform C2W;        /* current C2W xform */
  23.   Transform W2S;        /* camera-to-screen xform */
  24.   Transform O2S;        /* current object-to-screen xform */
  25.   void (*callback)(struct mgricontext *c, int event);
  26.  
  27.   Point3 cpos;                  /* current-coordinate position of camera
  28.                                  * (used for software normal flipping)
  29.                  * (and quickrenderman  line nudging */
  30.   int hascpos;                  /* cpos is valid */
  31.  
  32.     
  33.   /* following are for NeXTs */
  34.   char *nxwindow;        /* this is really an id */
  35.   char *nxview;            /* ditto */
  36.   RtToken qrmContext;        /* the QuickRenderman context */
  37.   RtToken windowresource;    /* each window has it's own context */
  38.   int debug;            /* debug flag to output ri code to ri.rib */
  39.   RtToken debugContext;        /* the context that will send ri to a file */
  40.   RtToken debugResource;    /* resource that will send ri to a file */
  41.   RtInt mgvorigin[2];        /* MGView origin - tells QRMAN where to draw */
  42.   int plni;            /* number of verticees in polyline buffer */
  43.   int plvi;            /* number of polylines in polyline buffer */
  44.   int plbuffsize;        /* size of the polyline buffer */
  45. } mgricontext;
  46.  
  47. /* These are totally private, should not (yet) be in mgri.h */
  48. enum {
  49.   MGRI_POLYGONS,
  50.   MGRI_POINTSPOLYGONS,
  51.   MGRI_DEVIDEDPOLYLIST
  52. };
  53.  
  54. #define _mgric        ((mgricontext*)_mgc)
  55. extern mgricontext *MGRI;    /* For debugging */
  56.  
  57. #define RI_X 0
  58. #define RI_Y 1
  59. #define RI_Z 2
  60.  
  61. #define GVMAXF 600 /* face drawing - vertices per RiPointsPolygons call */
  62. #define GVMAXL 400 /* edge drawing - ditto */
  63.  
  64. #define SCRATCHSIZE  1024*32
  65. extern RtPoint *ript;        /* points */
  66. extern RtColor *ricolor;    /* rgb color */
  67. extern RtPoint *rinormal;    /* normals */
  68. extern int *rippi;        /* PointsPolygon polygon index array */
  69. extern int rippis;        /* PointsPolygon polygon index array size */
  70. extern int *ripvi;        /* PointsPolygon vertex index array */
  71. extern int ripvis;        /* PointsPolygon vertex index array size */
  72. extern RtPoint *plp;          /* vertices */
  73. extern RtColor *plc;          /* colors */
  74. extern int *plvca;            /* polyline vertex count array */
  75. extern int *plvia;            /* vertex index array */
  76.  
  77. /* the renderman<->oogl transform */
  78. extern Transform cam2ri;
  79.  
  80. /* If you are running NS3.0 (default), uncomment the next line */
  81. #define NS_3_0_SLOW
  82.  
  83. /* If you are running NS3.1 or higher, comment out the above line and */
  84. /* uncomment this next line. This improves OFF and VECT performance   */
  85. /* but is still somewhat buggy as far as shading goes - performance only */
  86. /* #define NS_3_X_FAST */
  87.  
  88.  
  89.  
  90. /* here we define a simple routines to realloc scratch buffers if necessary */
  91. #define CHECK_VCN(nv,nc,nn)                        \
  92.     if(nv>SCRATCHSIZE) {                        \
  93.         ript = realloc(ript, nv*sizeof(RtPoint));            \
  94.     if(nc>SCRATCHSIZE) ricolor =                    \
  95.         realloc(ricolor, nc*sizeof(RtColor));            \
  96.     if(nn>SCRATCHSIZE) rinormal =                    \
  97.         realloc(rinormal, nn*sizeof(RtPoint));            \
  98.     }
  99. #define CHECK_VC(nv,nc)                            \
  100.     if(nv>SCRATCHSIZE) {                        \
  101.         ript = realloc(ript, nv*sizeof(RtPoint));            \
  102.     if(nc>SCRATCHSIZE) ricolor =                    \
  103.         realloc(ricolor, nc*sizeof(RtColor));            \
  104.     }
  105.  
  106. /* here we define a simple normalization routine for HPt3 -> RtPoint */
  107. /* we use this because it's somewhat faster then Hpt3Normalize       */
  108. #define mgri_normalize(src,rtpoint)                 \
  109.   { register HPoint3 *hpt3 = src;                \
  110.     *(Point3 *)(rtpoint) = *(Point3 *)(hpt3);            \
  111.     if(hpt3->w!=1. && hpt3->w!=0.0) {                \
  112.     rtpoint[RI_X]/=hpt3->w;                    \
  113.     rtpoint[RI_Y]/=hpt3->w;                    \
  114.     rtpoint[RI_Z]/=hpt3->w;                    \
  115.     }                                \
  116.    }
  117.  
  118. //void mgri_normalize(HPoint3 *p, RtPoint r);
  119.  
  120.  
  121. void mgri_drawline(HPoint3 *p1, HPoint3 *p2, Color *c);
  122. void mgri_drawpoint(HPoint3 *p);
  123. void mgri_plflush();
  124. void mgri_flushbuffer();
  125. void mgri_processevents();
  126. void mgri_closer();
  127.